package com.csw.clazzTeacher.service;

import java.util.Date;
import java.util.List;
import java.util.UUID;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.csw.clazzTeacher.dao.TagDAO;
import com.csw.clazzTeacher.entity.Tag;

/**
 * @author 1
 */
@Service("tagService")
@Transactional(rollbackFor = Exception.class)
public class TagServiceImpl implements TagService {

	@Autowired
	private TagDAO tagDAO;

	@Override
	public void save(Tag tag) {
		try {
			tag.setId(UUID.randomUUID().toString());// 生成主键
			tag.setCreateDate(new Date());// 生成创建时间
			tagDAO.save(tag);// 保存tag
		} catch (Exception e) {
			e.printStackTrace();
			throw new RuntimeException("保存标签信息错误..");
		}
	}

	@Override
	@Transactional(rollbackFor = Exception.class)
	public List<Tag> findAll() {
		List<Tag> list = tagDAO.queryAll();
		return list;
	}

	@Override
	@Transactional(rollbackFor = Exception.class)
	public List<Tag> findByTagType(String type) {
		List<Tag> list = tagDAO.queryByTagType(type);
		return list;
	}

}
